import { _decorator, Component, Node, Sprite, SpriteFrame } from 'cc';
import { Label } from 'cc';
import UtilTool from '../tools/UtilTool';
import { tween } from 'cc';
import { Vec3 } from 'cc';
import { App } from '../App';
const { ccclass, property } = _decorator;

/**
 * 通用奖励界面
 */
@ccclass('RewardBox')
export class RewardBox extends Component {

    @property(Node)
    bgNode : Node = null;

    @property(Label)
    label_coin : Label = null;

    @property(Node)
    title : Node = null;

    @property(Sprite)
    icon : Sprite = null;

    @property(SpriteFrame)
    iconArr = [];


    start() {
        UtilTool.nodeActive(this.bgNode, 5)
    }

    //type [0]金币 [1]星币
    initData(type,coinNumber) {
        // 显示金币数量
        this.label_coin.string = "+" + coinNumber 

        if (type==0) {
            this.icon.spriteFrame = this.iconArr[0]
        }
        else if (type==1) {
            this.icon.spriteFrame = this.iconArr[1]
        }

        tween(this.title)
            .to(0.2,{scale: new Vec3(1.2, 1.2, 1)})
            .to(0.3,{scale: new Vec3(0.8, 0.8, 1)})
            // .to(0.4,{scale: new Vec3(1.2, 1.2, 1)})
            // .to(0.4,{scale: new Vec3(0.8, 0.8, 1)})
            // .to(0.4,{scale: new Vec3(1.2, 1.2, 1)})
            .to(0.2,{scale: new Vec3(1, 1, 1)})
            .start()

        tween(this.icon.node)
            .to(0.3,{scale: new Vec3(1.2, 1.2, 1)})
            .to(0.4,{scale: new Vec3(0.8, 0.8, 1)})
            .to(0.3,{scale: new Vec3(1, 1, 1)})
            .start()

        tween(this.label_coin.node)
            .to(0.3,{scale: new Vec3(1.2, 1.2, 1)})
            .to(0.4,{scale: new Vec3(0.8, 0.8, 1)})
            .to(0.3,{scale: new Vec3(1, 1, 1)})
            .start()
    }

    /**确定 */
    clickSure() {
        App.Audio.playOneShot("click")
        this.node.destroy()
    }
    
}

